/**
 * 管理初始化
 */
var SmallInfo = {
    id: "SmallInfoTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
SmallInfo.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '主键', field: 'id', visible: true, align: 'center', valign: 'middle'}, 
            {title: '状态', field: 'status', visible: true, align: 'center', valign: 'middle',
            	formatter: function (value, row, index) {
                    if (value == '0') {
                        return "待审核";
                    }else if (value == '1') {
                        return "审核通过";
                    }else{
                    	return "审核不通过";
                    } 
                }	
            },
            {title: '小程序分类', field: 'type', visible: true, align: 'center', valign: 'middle'},
            {title: '小程序名称', field: 'name', visible: true, align: 'center', valign: 'middle'},
            {title: '图片url', field: 'url', visible: true, align: 'center', valign: 'middle',
              	formatter: function (value, row, index){
		      		if(value!=null && value!='' ){ 
		      			return "<span onclick=\"SmallInfo.imageClick('"+value+"')\"><img alt=\"-\"    class=\"img-rounded\"  src=\""+value+"\"  width=\"32px\" height=\"32px\"/></span>";
		      		}else{
		      			return"-"
		      		}
            	} 
            },
            {title: '小程序二维码url', field: 'qrCode', visible: true, align: 'center', valign: 'middle',
              	formatter: function (value, row, index){
		      		if(value!=null && value!='' ){ 
		      			return "<span onclick=\"SmallInfo.imageClick('"+value+"')\"><img alt=\"-\"    class=\"img-rounded\"  src=\""+value+"\"  width=\"32px\" height=\"32px\"/></span>";
		      		}else{
		      			return"-"
		      		}
            	} 
            }, 
            {title: '备注', field: 'remarks', visible: true, align: 'center', valign: 'middle'},
            {title: '联系方式', field: 'mobile', visible: true, align: 'center', valign: 'middle'},
            {title: '小程序标签', field: 'label', visible: true, align: 'center', valign: 'middle'},
            {title: '原始ID', field: 'ghId', visible: true, align: 'center', valign: 'middle'},
            {title: '修改时间', field: 'updateTime', visible: true, align: 'center', valign: 'middle'},
            {title: '爬取数据时间', field: 'scrapyTime', visible: true, align: 'center', valign: 'middle'}
    ];
};
/**
 * 点击图片
 */
SmallInfo.imageClick = function (src) { 
	   var html = "<span style=\"padding:50px;\" ><img alt=\"\"    class=\"img-rounded\"  src=\""+src+"\"  width=\"300px\" height=\"300px\"/></span>";
	 //在这里面输入任何合法的js语句
	   layer.open({
	     type: 1 //Page层类型
         ,shade:0.6 //遮罩
         ,shadeClose: true //shadeClose - 是否点击遮罩关闭 
	     ,area: ['400px', '350px']
	     ,title: '排污许可二维码'
	     ,maxmin: true //允许全屏最小化
	     ,anim: -1 //0-6的动画形式，-1不开启
	     ,content: html
	   });  
};

/**
 * 检查是否选中
 */
SmallInfo.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        SmallInfo.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加
 */
SmallInfo.openAddSmallInfo = function () {
    var index = layer.open({
        type: 2,
        title: '添加',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/smallInfo/smallInfo_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看详情
 */
SmallInfo.openSmallInfoDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/smallInfo/smallInfo_update/' + SmallInfo.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除
 */
SmallInfo.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/smallInfo/delete", function (data) {
            Feng.success("删除成功!");
            SmallInfo.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("smallInfoId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询列表
 */
SmallInfo.search = function () {
    var queryData = {};  
    queryData['name'] = $("#name").val();
    var status =  $("#status").val(); 
    debugger
    if("-1"!=status){
    	 queryData['status'] = status;
    }else{
    	queryData['status'] =-1;
    }
   
    SmallInfo.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = SmallInfo.initColumn();
    var table = new BSTable(SmallInfo.id, "/smallInfo/list", defaultColunms);
    table.setPaginationType("server");
    SmallInfo.table = table.init();
});
